<template>
  <div class="system-wrap" v-loading="loading">
    <template v-if="noticeList && noticeList.length">
      <teleport to="#simple-page">
        <el-pagination
          :total="total"
          :page-size="6"
          v-model:current-page="currentPage"
          layout="prev, slot, next"
          :prev-icon="CIconArrowLeft"
          :next-icon="CIconArrowRight"
          @current-change="handleCurrentChange"
        >
          <span class="page"> {{ totalPages ? currentPage : 0 }} / {{ totalPages }}</span>
        </el-pagination>
      </teleport>
      <el-row :gutter="16">
        <el-col :span="8" v-for="item in noticeList" :key="item.id">
          <div class="system-item" @click="toDialog(item)">
            <div class="left">
              <div class="top-tag-wrap" v-if="item.placedTop">
                <CIcon type="c-xian-zhiding" class="icon"></CIcon>
              </div>
              <div class="new-tag" v-if="item.newFlag">NEW</div>
              <c-icon type="c-xian-putongwenjian" class="g-mr4 icon"></c-icon>
              <span class="left-title" v-ellTooltip> {{ item.title }}</span>
            </div>
            <div class="right">{{ delTime(item.releaseTime) }}</div>
          </div>
        </el-col>
      </el-row>
      <Preview v-model:visible="dialogVisible" :info="dialogMain"></Preview>
    </template>
    <NoDataBox v-else name="当前暂无管理制度" hiddenImg></NoDataBox>
  </div>
</template>
<script lang="ts" setup>
import { useSystem } from './useSystem';
import Preview from '@/businessComponents/Preview/index.vue';
import NoDataBox from '../NoDataBox/index.vue';
import CIconArrowLeft from '@/components/CIconArrowLeft/index.vue';
import CIconArrowRight from '@/components/CIconArrowRight/index.vue';
const {
  noticeList,
  dialogMain,
  dialogVisible,
  toDialog,
  totalPages,
  total,
  currentPage,
  loading,
  handleCurrentChange
} = useSystem();

const delTime = (dateStr: string) => {
  let arr = dateStr.split(' ');
  if (arr.length) {
    return arr[0];
  }
  return dateStr;
};
</script>

<style lang="scss" scoped>
.system-wrap {
  background: #ffffff;
  height: 92px;
  width: 100%;
  padding: 0 6px;
  border-radius: 0 0 6px 6px;
  .system-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    height: 36px;
    border-radius: 2px;
    cursor: pointer;
    padding: 0 12px;
    border-radius: 2px;
    &:hover {
      background: #edf2f7;
      .left > .left-title {
        color: #03ac82;
      }
    }
    .left {
      // margin-right: 40px;
      width: calc(100% - 108px);
      display: flex;
      align-items: center;
      .left-title {
        display: inline-block;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #435970;
        line-height: 22px;
        flex: 1;
      }
    }
    .right {
      font-size: 12px;
      font-family: HelveticaNeue;
      color: #7a8a99;
      line-height: 20px;
      width: 70px;
      text-align: right;
    }
  }
  .top-tag-wrap {
    margin-right: 6px;
    width: 16px;
    height: 16px;
    background: #03ac82;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    .icon {
      font-size: 12px;
      color: #ffffff;
    }
  }
  .new-tag {
    width: 36px;
    height: 16px;
    background: linear-gradient(137deg, #ffa753 0%, #ff4829 100%);
    border-radius: 3px;
    line-height: 16px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: #ffffff;
    margin-right: 6px;
  }
  .page {
    font-size: 14px;
    font-family: HelveticaNeue;
    color: #435970;
    line-height: 22px;
  }
}
</style>
